package com.ruoyi.web.controller.laiqianba.member;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.db.domain.MerchantDataPoolInfo;
import com.ruoyi.db.domain.MerchantDataPushInfo;
import com.ruoyi.merchant.service.IMerchantDataPushInfoService;
import com.ruoyi.merchantdata.service.IMerchantDataPoolInfoService;
import com.ruoyi.web.wrapper.MerchantDataPushInfoWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 用户推送信息Controller
 */
@Slf4j
@RestController
@RequestMapping("/member/pushInfo")
public class MerchantPushInfoController extends BaseController
{
    @Autowired
    private IMerchantDataPushInfoService merchantDataPushInfoService;
    @Autowired
    private IMerchantDataPoolInfoService merchantDataPoolInfoService;

    /**
     * 查询商户推送信息列表
     *
     */
    @PreAuthorize("@ss.hasPermi('member:push:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantDataPushInfo merchantDataPushInfo)
    {
        log.info("【数据请求】【uid】{}【merchant】{}", SecurityUtils.getUserId(), JSON.toJSONString(merchantDataPushInfo));

        List<Map<String, Object>> Apilist = merchantDataPushInfoService.selectMerchantDataPushInfoMapList(merchantDataPushInfo);
        MerchantDataPoolInfo merchantDataPoolInfo = new MerchantDataPoolInfo();

        merchantDataPoolInfo.setUid(merchantDataPushInfo.getUid());
        List<Map<String, Object>> Crmlist = merchantDataPoolInfoService.selectMerchantDataPoolInfo(merchantDataPoolInfo);

        List<Map<String, Object>> list = new ArrayList<>();
        list.addAll(Apilist);
        list.addAll(Crmlist);

        list = new MerchantDataPushInfoWrapper(list).wrap();
        return getDataTable(list);
    }


}
